﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PRO.DbProvider;
using PRO.Entity;
using PRO.ORM;
using PRO.Common;

namespace PRO.CashCoupon
{
    public class CashCouponLib
    {
        /// <summary>
        /// 创建礼品卡卡号
        /// </summary>
        /// <returns></returns>
        public static string CreateCardNumber()
        {
            StringBuilder str = new StringBuilder();
            Random myRandom = new Random(Guid.NewGuid().GetHashCode());
            str.Append(myRandom.Next(1000, 9999));
            myRandom = new Random(Guid.NewGuid().GetHashCode());
            str.Append(myRandom.Next(1000, 9999));
            myRandom = new Random(Guid.NewGuid().GetHashCode());
            str.Append(myRandom.Next(1000, 9999));
            //myRandom = new Random(Guid.NewGuid().GetHashCode());
            //str.Append(myRandom.Next(1000, 9999));
            return str.ToString();
        }
        /// <summary>
        /// 创建礼品卡
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static bool CreateCashCoupon(CashCouponInfo info)
        {
            if (DataBaseProvider.GetInstance().CreateCashCoupon(info) > 0)
                return true;
            else
                return false;
        }
        /// <summary>
        /// 设置已经卖出
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool SetSoldOver(int id)
        {
            return DataBaseProvider.GetInstance().SetSoldOver(id);
        }
        /// <summary>
        /// 删除礼品卡
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool DelCashCoupon(int id)
        {
            return DataBaseProvider.GetInstance().DelCashCoupon(id);
        }
        /// <summary>
        /// 获取礼品卡信息
        /// </summary>
        /// <param name="number">卡号</param>
        /// <returns></returns>
        public static CashCouponInfo GetCashCoupon(string number)
        {
            if (number.Length == 12)
            {
                if (number.IsNumber())
                {
                    CashCouponInfo info = new CashCouponInfo();
                    info.BindDataToEntity(DataBaseProvider.GetInstance().GetCashCoupon(number));
                    return info;
                }
            }
            return null;
        }
    }
}
